﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class 数据访问控件_读取Excel文件 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string   connstr;
        connstr = "Provider=MicroSoft.Jet.OleDb.4.0;Data Source =" + "d:\\My Documents\\面试题.xls" + ";Extended Properties=Excel 8.0";
        OleDbConnection MyConn = new OleDbConnection(connstr);

        MyConn.Open();

        DataSet Myds = new DataSet();
        OleDbDataAdapter MyOleDbDa = new OleDbDataAdapter("select * from [sheet1$]", MyConn);
        MyOleDbDa.Fill(Myds);

        GridView1.DataSource = Myds.Tables[0].DefaultView;
        GridView1.DataBind();
       
        MyConn.Close();

    }
}
